﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LPY.LeHealth.DTO;
namespace LPY.LeHealth.DAL
{
    using ServiceStack.OrmLite;
    public class Combo_TypeDAL:BaseDAL
    {
        /// <summary>
        /// 套餐类添加
        /// </summary>
        /// <param name="combo_tyoe"></param>
        /// <returns></returns>
        public bool Add(ComboTypeDTO combo_tyoe)
        {
            var rtv = DbConnection.Insert<ComboTypeDTO>(combo_tyoe);
            return rtv > 0;
        }


        /// <summary>
        ///根据体检套餐类型名称，获取体检套餐类型id
        /// </summary>
        /// <param name="combo_type"></param>
        /// <returns></returns>
        public int getComboTypeIdByName(string combo_type)
        {
            using (var cnn = DbConnection)
            {
                var sql = cnn.From<ComboTypeDTO>()
                    .Where(m => m.Name == combo_type);
                
                var rtv = cnn.Select(sql).FirstOrDefault();
                if(rtv==null)
                {
                    return 0;
                }

                return rtv.Id;
            }

        }



        /// <summary>
        ///获取全部体检套餐类型
        /// </summary>
        /// <param name="combo_type"></param>
        /// <returns></returns>
        public List<ComboTypeDTO> getComboType()
        {
            using (var cnn = DbConnection)
            {
                var sql = cnn.From<ComboTypeDTO>();

                var rtv = cnn.Select(sql).ToList();
                

                return rtv;
            }

        }


    }
}
